package com.csun.nusing.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.csun.nusing.R;
import com.csun.nusing.bean.jsonbean.FileSearchJsonBean;
import com.csun.nusing.bean.jsonbean.NursingOldrestListJsonBean.NursingOldrestDataBean.NursingOldrestListBean;
import com.csun.nusing.ui.myview.RoundImageView;

import java.util.List;

/**
 * 老人界面的适配器 ClassName: NursingOldrestAdapter
 * 
 * @Description: TODO
 * @author fzq
 * @date 2017-10-27
 */
public class NursingOldrestAdapter extends BaseAdapter {

	private Context context;
	private List<NursingOldrestListBean> listdata;
	private LayoutInflater inflater;
	protected FileSearchJsonBean fillsearchbean;
	private String authorization;

	public NursingOldrestAdapter(Context context,
			List<NursingOldrestListBean> listdate) {
		this.context = context;
		this.listdata = listdate;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return listdata.size();
	}

	@Override
	public Object getItem(int position) {
		return listdata.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		// 重用convertView
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_nursing_oldrest_list,
					null);
			viewHolder = new ViewHolder();
			viewHolder.statetv = convertView
					.findViewById(R.id.item_nursingoldrest_list_state_tv);
			viewHolder.phonetv = convertView
					.findViewById(R.id.item_nursingoldrest_list_phone_tv);
			viewHolder.headeriv = (RoundImageView) convertView
					.findViewById(R.id.item_nursingoldrest_list_header_iv);
			viewHolder.bgiv = convertView
					.findViewById(R.id.item_nursing_olderst_iv);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		// 操作
		if (listdata.get(position) != null) {
			Glide.with(context).load(listdata.get(position).getHeadPicture())
					.into(viewHolder.headeriv);
			viewHolder.statetv.setText("" + listdata.get(position).getName());
			viewHolder.phonetv.setText("" + listdata.get(position).getPhone());
			if (listdata.get(position).getStatus() == 0) {
				// 未入院
				viewHolder.bgiv
						.setImageResource(R.drawable.olderlist_item_weichuyuan_bg);
			} else if (listdata.get(position).getStatus() == 1) {
				// 以入院
				viewHolder.bgiv.setImageResource(R.drawable.laoren_list_bg_hg);
			} else {
				// 出院
				viewHolder.bgiv
						.setImageResource(R.drawable.olderlist_item_chuyuan_bg);
			}
		}
		return convertView;
	}

	/**
	 * ClassName: ViewHolder
	 * 
	 * @Description: TODO
	 * @author fzq
	 * @date 2017-10-27
	 */
	private class ViewHolder {
		private TextView statetv;
		private TextView phonetv;
		private ImageView headeriv;
		private ImageView bgiv;

	}

}
